Package org.jruby.test

Source Code of org.jruby.test.TestArrayFlatten

package org.jruby.test;

import junit.framework.TestCase;

import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.runtime.Block;
import org.jruby.runtime.builtin.IRubyObject;

public class TestArrayFlatten extends TestCase {

    public void testFlatten() throws Exception {
        Ruby runtime = Ruby.newInstance();
        RubyArray keys = runtime.newArray();
        RubyArray values = runtime.newArray();
       
//        int n = 10;
        int n = 10000;
        for (int i = 0; i < n; ++i) {
            keys.append(runtime.newFixnum(i));
            values.append(runtime.newFixnum(i));
        }
       
        RubyArray temp = (RubyArray) keys.zip(runtime.getCurrentContext(), new IRubyObject[] {values}, Block.NULL_BLOCK);
        RubyArray preHash = (RubyArray) temp.flatten(runtime.getCurrentContext());
       
        assertNotNull("We have a hash back", preHash);
    }
}
TOP

Related Classes of org.jruby.test.TestArrayFlatten

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.